﻿using BCCommon;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace BCService.Common.OSS
{
    /// <summary>
    /// 阿里云对象存储
    /// </summary>
    public class OSS : IOSS
    {
        private readonly IConfiguration configuration;
        private string endpoint;
        public string accessKeyId;
        public string accessKeySecret;
        // 设置回调请求的服务器地址。
        public string callbackUrl;
        // 设置发起回调时请求body的值。
        public string callbackBody;
        
        public OSS(IConfiguration configuration)
        {
            this.configuration = configuration;
            Init();
        }

        private void Init()
        {
            endpoint = configuration["AliyunOSSAPI:EndPoint"];
            accessKeyId = configuration["AliyunOSSAPI:AccessKeyID"];
            accessKeySecret = configuration["AliyunOSSAPI:AccessKeySecret"];
            callbackUrl = configuration["AliyunOSSAPI:Buckets:0:buckets"];
            callbackBody = "bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&upload_file_record_no=${x:upload_file_record_no}";
    }

        public string GetEndpoint()
        {
            return endpoint;
        }

        public string GetAccessKeyId()
        {
            return accessKeyId;
        }

        public string GetAccessKeySecret()
        {
            return accessKeySecret;
        }

        public string GetCallbackUrl()
        {
            return callbackUrl;
        }

        public string GetCallbackBody()
        {
            return callbackBody;
        }
    }
}
